package pattern.singleton;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.io.*;

public class Test01 {
    public static void main(String[] args) throws CloneNotSupportedException, IOException, ClassNotFoundException {
//        Single single = Single.getInstance();
//        Single single1 = Single.getInstance();
//        System.out.println(single);
//        System.out.println(single1);

        Student student = new Student("张飞",30);
        student.setClassz(new Classz());
//        Student student1 = (Student)student.clone();

//        System.out.println(student);
//        System.out.println(student1);
//        System.out.println(student == student1);
//        System.out.println(student.getClassz() == student1.getClassz());


        // 深度克隆
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(byteArrayOutputStream);
        oos.writeObject(student);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(byteArrayInputStream);
        Student student2 = (Student) ois.readObject();

        System.out.println(student2);
        System.out.println(student == student2);
        System.out.println(student.getClassz() == student2.getClassz());


    }
}
